package beike;

import java.util.List;

public class Main1 {

    public static void main(String[] args) {
        long[] res = FarmerNN(4, 6);
        for (int i = 0; i < 4; i++){
            System.out.println(res[i]);
        }

    }

    public static long[] FarmerNN (int n, long m) {
        // write code here
        long[] nums = new long[n];
        long count = m/(n - 1);
        long x = m%(n - 1);
        if (count % 2 == 1){
            nums[0] = count/2 + 1;
            nums[n - 1] = count/2;
            for (int i = 1; i < n - 1; i++){
                nums[i] = count + 1;
            }
            int index = n - 1;
            while (x > 0){
                nums[index]++;
                x--;
                index--;
            }
        } else {
            nums[0] = count/2;
            nums[n - 1] = count/2;
            for (int i = 1; i < n - 1; i++){
                nums[i] = count;
            }
            int index = 0;
            while (x > 0){
                nums[index]++;
                x--;
                index++;
            }
        }
        return nums;
    }

    public static long[] FarmerNN2 (int n, long m) {
        long[] res = new long[n];
        if(m<=n){
            for(int i=0;i<m;++i){
                res[i] = 1;
            }
            return res;
        }
        for(int i=0;i<n;++i){
            res[i] = 1;
        }
        m = m-n;
        //int r = m%(n-1);
        long x = m/(n-1);
        long r = m-x*(n-1);
        if(x%2==0){
            res[0] += x/2;
            res[n-1] += x/2;
            for(int i=1;i<n-1;++i)
                res[i]+=x;
            for(int i=n-2;r>0;i--,r--)
                res[i] += 1;
        }
        else{
            res[0] += x/2;
            res[n-1] += x/2;
            res[0] += 1;
            for(int i=1;i<n-1;++i)
                res[i]+=x;
            for(int i=1;r>0;i++,r--)
                res[i] += 1;
        }
        return res;
    }


}
